package com.gl.controller;


import com.gl.service.TPayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-12-14
 */
@RestController
@RequestMapping("/paylog")
public class TPayLogController {

    @Autowired
    private TPayLogService payLogService;

    //根据订单号，生成支付信息，包括二维码地址
    @GetMapping("createPayInfo/{orderNo}")
    public Map createPayInfo(@PathVariable String orderNo){
        Map<String,Object> map = payLogService.createPayInfo(orderNo);
        return map;
    }

    //查询订单支付状态
    @GetMapping("queryPayStatus/{orderNo}")
    public Map queryPayStatus(@PathVariable String orderNo){
        Map resultMap = new HashMap();
        Map<String,String> map = payLogService.queryPayStatus(orderNo);
        if(map == null){
            resultMap.put("msg","支付出错了");
        }
        //如果返回map里面不为空，通过map获取订单状态
        if(map.get("trade_state").equals("SUCCESS")){//支付成功
            //添加记录到支付表，更新订单表订单状态
            payLogService.updateOrderStatus(map);
            resultMap.put("msg","支付成功");
        }

        return resultMap;
    }

}

